package net.mikoo.seals.api.model.verify;

import java.util.ArrayList;
import java.util.List;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.common.enums.VerifyStatusEnum;
import net.mikoo.seals.common.model.PageModel;
import net.mikoo.seals.model.ApplyVerify;

public class VerifyListResponse extends BaseResponse {

	private static final long serialVersionUID = 5239210526416772998L;

	private List<VerifyInfo> verifyInfos;
	
	public List<VerifyInfo> getVerifyInfos() {
		return verifyInfos;
	}

	public void setVerifyInfos(List<VerifyInfo> verifyInfos) {
		this.verifyInfos = verifyInfos;
	}

	public static VerifyListResponse valueOf(PageModel<ApplyVerify> pm) {
		VerifyListResponse result = new VerifyListResponse();
		
		if(pm == null || pm.getDatas() == null || pm.getDatas().isEmpty()) {
			return result;
		}
		
		List<VerifyInfo> verifyInfoList = new ArrayList<VerifyInfo>();
		for(ApplyVerify verify : pm.getDatas()) {
			if(verify == null) {
				continue;
			}
			
			VerifyInfo verifyInfo = new VerifyInfo();
			verifyInfo.setVerifyId(verify.getApplyVerifyId());
			VerifyStatusEnum verifyStatus = VerifyStatusEnum.getByCode(verify.getVerifyStatus());
			if(verifyStatus != null) {
				verifyInfo.setStatus(verify.getVerifyStatus());
				verifyInfo.setStatusName(verifyStatus.getMessage());
			}
			verifyInfo.setName(verify.getApply().getSeal().getSealName());
			verifyInfo.setDescription(String.format("%s申请使用", verify.getApply().getPerson().getName()));
			verifyInfo.setApplyType(verify.getApply().getApplyType());
			verifyInfoList.add(verifyInfo);
		}
		result.setVerifyInfos(verifyInfoList);
		return result;
	}
	
}
